import request from "@/utils/request";
import { encryptedData } from "@/utils/encrypt";
import { loginRSA } from "@/config/settings";

export async function login(data) {
  let second = Date.parse(new Date()).toString();
  data.timestamp = second.substr(0, 10);
  if (loginRSA) {
    data = await encryptedData(data);
  }

  return request({
    url: "/login",
    method: "post",
    data: data,
  });
}

export function getUserInfo(accessToken) {
  return request({
    url: "/admin/info",
    method: "post",
    data: {
      token: accessToken,
    },
  });
}

export function logout() {
  return request({
    url: "/logout",
    method: "post",
  });
}

export function register() {
  return request({
    url: "/register",
    method: "post",
  });
}
